
var checkEarlyWarningdelid=[];
var seeDetails;
$(function () {

  var modifypicThat;
  var modifyformData = {};
  var modifyformData1 = {};
  var modifyformData2 = {};
  var modifyformData3 = {};
  var modifyformData4 = {};
  // 三色预警场所列表展示
  var earlyWarningPageSum;
  var earlyWarningPageNum = 1;

  function formatDuring(mss) {
    var days = Math.ceil(mss / (1000 * 60 * 60 * 24));
    var hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
    var minutes = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60));
    var seconds = (mss % (1000 * 60)) / 1000;
    // return days + " 天 " + hours + " 小时 " + minutes + " 分钟 " + seconds + " 秒 ";
    return days + " 天 ";
  }
  $(".earlyWarning-trigger").on("click", function (event) {
    event.preventDefault();
    // 关闭 GPS 页面
    $('.bgBox').hide();
    pageMenuOff = true;
    $(".earlyWarning-pop").addClass("is-visible3");
    // 三色预警列表
    // earlyWarningPageList(1);

    var ret = getThreeColorGetRectifyInfo({
      size: 10,
      page: 0
    });
    ret.then(function (data) {
      $('#earlyWarningModal .tbodyList').html('');
      $("#earlyWarningModal .devAddress").val('');
      $('#earlyWarningModal .searchFilter .leveliskItem').removeClass('active');
      $('#earlyWarningModal .searchFilter .leveliskItem').eq(0).addClass('active');
      levelisk = 0;
      var content = data.data.content;
      var appearTime = '';
      var leveliskStr = '';
      earlyWarningPageSum = data.data.totalPages;
      console.log(data.data.content);
      // 给自定义属性赋值 data-onlyvalue
      for (var i = 0; i < content.length; i++) {
        leveliskStr = content[i].tcw.levelisk;
        if (leveliskStr <= 1) {
          leveliskStr = '一般';
        } else if (leveliskStr == 2) {
          leveliskStr = '较大';
        } else if (leveliskStr == 3) {
          leveliskStr = '高危';
        } 
        appearTime = moment(content[i].tcw.appearTime).format('YYYY-MM-DD HH:mm:ss');
        // $('#earlyWarningModal .tbodyList').append('<tr><td><input type="checkbox" class="check" onlyvalue="' + data.data.content[i].onlyValue + '"devid="' + content[i].id + '"></td><td>' + ((+i) + (+1)) + '</td><td>' + content[i].manager + '/' + content[i].telephone + '</td><td>' + content[i].unit + '</td><td>' + leveliskStr + '</td><td>' + appearTime + '</td><td><span class="seeDetailsStyle earlyWarningSeeDetails" orgid ="' + content[i].organization.id + '" id ="' + content[i].id + '" data-onlyvalue="' + data.data.content[i].onlyValue + '">查看详情</span><span class="modifyBtnStyle" onlyvalue="' + data.data.content[i].onlyValue + '">整改</span><span class="earlyWarningPosition earlyWarning-pop positionBtn" devCode="' + content[i].onlyValue + '"longitude="' + content[i].longitude + '" latitude="' + content[i].latitudes + '">定位</span></td></tr>'); //
        var rectifyTime = content[i].rectifyTime;
        rectifyTime = formatDuring(rectifyTime);
        var rectification = content[i].rectification;
        var rectificationStr = '一般';
        if(rectification == 1){
          rectificationStr = '一般';
        }else if(rectification == 2){
          rectificationStr = '较大';
        }else if(rectification == 3){
          rectificationStr = '高危';
        }
        $('#earlyWarningModal .tbodyList').append('<tr><td><input onlyValue="' + data.data.content[i].tcw.onlyValue + '" type="checkbox" class="check" devid="' + content[i].tcw.id + '"></td><td>' + ((+i) + (+1)) +                    '</td><td>' + content[i].tcw.manager + '/' + content[i].tcw.telephone + '</td><td>' + content[i].tcw.unit + '</td><td>' + leveliskStr + '</td><td>' + content[i].rectifyProgress + '</td><td>' + rectifyTime + '</td><td>' + rectificationStr + '</td><td>' + appearTime + '</td><td><span class="seeDetailsStyle earlyWarningSeeDetails" orgid ="' + content[i].tcw.organization.id + '" id="' + content[i].tcw.id + '" data-onlyvalue="' + data.data.content[i].tcw.onlyValue + '"  data-qrCode="' + data.data.content[i].tcw.unit+ '">详情</span><span class="earlyWarningPosition earlyWarning-pop positionBtn" devCode="' + content[i].tcw.onlyValue + '"longitude="' + content[i].tcw.longitude + '" latitude="' + content[i].tcw.latitudes + '">定位</span><span class="earlyWarningRectifyBtn earlyWaringRectify-trigger seeRectifyStyle" onlyvalue="' + data.data.content[i].tcw.onlyValue + '">整改过程</span><span class="modifyBtnStyle" onlyvalue="' + data.data.content[i].tcw.onlyValue + '">整改</span><span class="earlyWarningQrcode1 earlyWarningQrcode'+data.data.content[i].tcw.onlyValue+'" style="display: none;"></span><a id="download" download="qrcode1.jpg"></a><span class="earlyWarningsaveQrCode" style="cursor: pointer;">下载</span></td></tr>');

      }

      earlyWarningPageFunc(earlyWarningPageSum, 0);
      
    }).catch(function (err) {
      console.log(err);
    });
  });
  // $('#earlyWarningModal').on('click','.earlyWarningPosition',function (){
  //   var $this = $(this);
  //   var longitude = $this.attr('longitude');
  //   var latitude = $this.attr('latitude');
  //   var devCode = $this.attr('devCode');
  //   console.log(longitude, latitude);
  //   BaiDuMap.panTo(latitude, longitude);
  //   setTimeout(function () {
  //     BaiDuMap.popMenu(devCode);
  //   }, 700);
  //   if ($(event.target).is('.cd-popup-close') || $(event.target).is('.earlyWarning-pop')) {
  //     event.preventDefault();
  //     $('.earlyWarning-pop').removeClass('is-visible3');
  //   }
  //   for(var i=0;i<earlyWarningMarker.length;i++){
  //     if(earlyWarningMarker[i].devCode == devCode){
  //       earlyWarningMarker[i].showOver();
  //     }
  //   }
  // });
  // 点击等级筛选
  $('#earlyWarningModal .searchFilter .leveliskItem').on('click', function () {
    earlyWarningPageNum = 1;
    $(this).addClass('active').siblings().removeClass('active');
    earlyWarningPageList(earlyWarningPageNum);
  });
  // 点击搜索按钮
  var earlyWarningClickSearchFn = _.debounce(function () {
    earlyWarningPageList(1);
  }, 500);
  $('#earlyWarningModal .searchBox .earlyWarningSearchBtn').on('click', function () {
    earlyWarningClickSearchFn();
  });
  // 模糊查询
  searchFunc();

  function searchFunc() {
    //模糊查询
    $('body').on('click', function () {
      $("#earlyWarningModal .searchList").hide();
    });
    var fn = _.debounce(function () {
      $("#earlyWarningModal .searchList").show();
      hide2border();
      if ($("#earlyWarningModal .searchList li")) { //键盘抬起后就判断页面中是否存在这个元素,存在就删除
        $("#earlyWarningModal .searchList li").remove();
      }
      var searchContent = $("#earlyWarningModal .devAddress").val();
      searchContent = $.trim(searchContent);
      console.log(searchContent)
      if (searchContent) {
        var unit = '&unit=' + searchContent;
      } else {
        var unit = '';
        $("#earlyWarningModal .searchList").html('');
      }

      //查询内容存在则搜索
      if (searchContent) {
        $.ajax({
          url: "/threeColor/getInfo?size=1000&page=0" + unit,
          type: "GET",
          // async: false,
          success: function (result) {
            console.log(result)
            var data = result.data.content;
            if (data.length <= 10) {
              for (var i = 0; i < data.length; i++) {
                var unit = data[i].unit;
                $("#earlyWarningModal .searchList").append('<li>' + unit + '</li>');
                hide2border();
              }
            }
          }
        });
      }
      $("#earlyWarningModal .searchList").show();
      hide2border();
    }, 500);
    $("#earlyWarningModal .devAddress").on("input", function (e) {
      fn();
    });
    //直接输入地址,点击列表查询
    $("#earlyWarningModal .searchList").on("click", "li", function () {
      $("#earlyWarningModal .searchList").show();
      var liVal = $(this).text();
      liVal = $.trim(liVal);
      var searchVal = $("#earlyWarningModal .devAddress").val(liVal);

      $("#earlyWarningModal .searchList").html(""); //hide
      return false;
    });
  }

  function hide2border() {
    if (!($("#earlyWarningModal .searchList>li").length)) {
      $("#earlyWarningModal .searchList").hide();
    } else {
      $("#earlyWarningModal .searchList").show();
    }
  }
  //三色预警场所  关闭窗口
  $(".earlyWarning-pop").on("click", function (event) {
    if (
      $(event.target).is(".cd-popup-close") ||
      $(event.target).is(".earlyWarning-pop")
    ) {
      event.preventDefault();
      $(this).removeClass("is-visible3");
    }
  });
  //设备管理  分页功能
  function earlyWarningPageFunc(pageSum, startPageNum) {
    console.log(pageSum)
    if (pageSum <= 1) {
      $('#earlyWarningPageBox .pageJump').hide()
    } else {
      $('#earlyWarningPageBox .pageJump').show()
    }
    Page({
      num: pageSum, //页码数
      startnum: startPageNum, //指定页码
      elem: $('#earlyWarningPage'), //指定的元素
      callback: function (n) { //回调函数
        earlyWarningPageNum = n;
        // $('#earlyWarningPageBox .pageJump').show();
        earlyWarningPageList(n);
        // 当翻到下一页时 清除掉 全选按钮的 选中状态
        $("#earlyWarningSelectAll").prop("checked", false);
      }
    });
  }

  function earlyWarningPageList(n) {
    var userId = localStorage.getItem('userId');
    var levelisk = $('#earlyWarningModal .searchFilter span.active').attr('levelisk');
    var unit = $('#earlyWarningModal .searchBox input').val();

    var obj = {};
    if(n<1){
      n = 1;
    }
    obj.size = 10;
    obj.page = n - 1;

    if (unit) {
      obj.unit = unit;
    }
    if (levelisk != '0') {
      obj.levelisk = levelisk;
    }
    // console.log(userId,levelisk)
    var ret = getThreeColorGetRectifyInfo(obj);
    ret.then(function (data) {
      $('#earlyWarningModal .tbodyList').html('');
      var content = data.data.content;
      var appearTime = '';
      var levelisk = '';
      earlyWarningPageSum = data.data.totalPages;
      console.log(data);
      console.log(data.data.content);
      // 给自定义属性赋值 data-onlyvalue
      for (var i = 0; i < content.length; i++) {
        levelisk = content[i].tcw.levelisk;
        if (levelisk <= 1) {
          levelisk = '一般';
        } else if (levelisk == 2) {
          levelisk = '较大';
        } else if (levelisk == 3) {
          levelisk = '高危';
        }
        appearTime = moment(content[i].tcw.appearTime).format('YYYY-MM-DD HH:mm:ss');
        var rectifyTime = content[i].rectifyTime;
        rectifyTime = formatDuring(rectifyTime);
        var rectification = content[i].rectification;
        var rectificationStr = '一般';
        if(rectification == 1){
          rectificationStr = '一般';
        }else if(rectification == 2){
          rectificationStr = '较大';
        }else if(rectification == 3){
          rectificationStr = '高危';
        }
        $('#earlyWarningModal .tbodyList').append('<tr><td><input onlyValue="' + data.data.content[i].tcw.onlyValue + '" type="checkbox" class="check" devid="' + content[i].tcw.id + '"></td><td>' + ((+n - 1) * (+10) + (+i) + (+1)) + '</td><td>' + content[i].tcw.manager + '/' + content[i].tcw.telephone + '</td><td>' + content[i].tcw.unit + '</td><td>' + levelisk + '</td><td>' + content[i].rectifyProgress + '</td><td>' + rectifyTime + '</td><td>' + rectificationStr + '</td><td>' + appearTime + '</td><td><span class="seeDetailsStyle earlyWarningSeeDetails" orgid ="' + content[i].tcw.organization.id + '" id="' + content[i].tcw.id + '" data-onlyvalue="' + data.data.content[i].tcw.onlyValue + '" data-qrCode="' + data.data.content[i].tcw.unit+ '">详情</span><span class="earlyWarningPosition earlyWarning-pop positionBtn" devCode="' + content[i].tcw.onlyValue + '"longitude="' + content[i].tcw.longitude + '" latitude="' + content[i].tcw.latitudes + '">定位</span><span class="earlyWarningRectifyBtn earlyWaringRectify-trigger seeRectifyStyle" onlyvalue="' + data.data.content[i].tcw.onlyValue + '">整改过程</span><span class="modifyBtnStyle" onlyvalue="' + data.data.content[i].tcw.onlyValue + '">整改</span><span class="earlyWarningQrcode1 earlyWarningQrcode'+data.data.content[i].tcw.onlyValue+'" style="display: none;"></span><a id="download" download="qrcode1.jpg"></a><span class="earlyWarningsaveQrCode" style="cursor: pointer;">下载</span></td></tr>');

      }

      earlyWarningPageFunc(earlyWarningPageSum, n);
    }).catch(function (err) {
      console.log(err);
    });
  }


  // 删除按钮
  // 全选或者 全不选
  // 设置 全选按钮的选中状态 allcheck
  $("#earlyWarningSelectAll").on("click", function () {
    var allcheck = $("#earlyWarningSelectAll").prop("checked");
    $("#earlyWarningModal .tbodyList .check").prop("checked", allcheck);
  });
  // 反选
  $("#earlyWarningModal .tbodyList").on("click", '.check', function () {
    var length1 = $("#earlyWarningModal .tbodyList").find(":checkbox").length;
    var length2 = $("#earlyWarningModal .tbodyList").find(":checked").length;
    if (length1 == length2) {
      $("#earlyWarningSelectAll").prop("checked", true);
    } else {
      $("#earlyWarningSelectAll").prop("checked", false);
    }
  });
  // 删除列表
  $("#earlyWarningDelBtn").on("click", function () {
    if ($('#earlyWarningSelectAll').prop("checked")) {
      earlyWarningPageNum = earlyWarningPageNum - 1;
    }
    // $('#configurationModal .table .tbodyList input[type=checkbox]:checked').each(function ()
    $("#earlyWarningModal .tbodyList").find(":checked").each(function (index, ele) {
      // 获取自定义属性的值 devid
      var devid = $(this).attr("devid");
      var onlyValue = $(this).attr("onlyValue");
      $.ajax({
        url: '/threeColor/del?onlyValue=' + onlyValue,
        // async: false,  同步
        type: 'post',
        data: {
          _method: "DELETE"
        },
        dataTpe: "json",
        success: function (res) {
          console.log(res);
          // BaiDuMap.deletePoint(onlyValue);
          deleteEarlyWarningPoint(onlyValue);
          $('#earlyWarningSelectAll').prop("checked", false);
          console.log(earlyWarningPageSum, earlyWarningPageNum)
          earlyWarningPageFunc(earlyWarningPageSum, earlyWarningPageNum)
          earlyWarningPageList(earlyWarningPageNum);
          tipModalFunc('删除成功');
        },
        error: function (res) {
          console.log(res);
        }
      });
    });
  });
  // 获取三色预警添加、查看、修改的组织
  var ret = getOrganizationList();
  ret.then(function (data) {
    console.log(data);
    $('#addEarlyWarningForm .addEarlyWarningOrgList').html('');
    $('#checkEarlyWarningDetails .addEarlyWarningOrgList').html('');
    $('#modifyEarlyWarningDetails .modifyEarlyWarningDetailsorgId').html('');
    for (var i = 0; i < data.data.length; i++) {
      $('#addEarlyWarningForm .addEarlyWarningOrgList').append('<option value="' + data.data[i].id + '">' + data.data[i].orgName + '</option>')
      $('#checkEarlyWarningDetails .addEarlyWarningOrgList').append('<option value="' + data.data[i].id + '">' + data.data[i].orgName + '</option>')
      $('#modifyEarlyWarningDetails .modifyEarlyWarningDetailsorgId').append('<option value="' + data.data[i].id + '">' + data.data[i].orgName + '</option>')
    }
  }).catch(function (err) {
    console.log(err);
  });

  //---------------三色预警添加  打开窗口--------------
  // // 添加时间
  // var appearTime = moment().format('YYYY-MM-DD');
  // $('#addEarlyWarningForm .appearTimeVal').val(appearTime);
  $(".addEarlyWarning-trigger").on("click", function (event) {
    event.preventDefault();
    $(".addEarlyWarning-pop").addClass("is-visible3");
    $('#addEarlyWarningForm .leveliskVal').val('一般');

    // 图片按顺序上传 除第一个框之外都 设禁用
    // $('#addEarlyWarningForm .earlyWarningPhoto li:not(:first)').find(".upload").attr("disabled", true);
    // $('#addEarlyWarningForm .earlyWarningPhoto li:not(:first)').addClass('earlyWarningPhotoDisabled');

    // 获取所有组织
    var getOrganizationListRet = getOrganizationList();
    getOrganizationListRet.then(function (data) {
      console.log(data);
      $('#addEarlyWarningForm .addEarlyWarningOrgList').html('');
      for (var i = 0; i < data.data.length; i++) {
        $('#addEarlyWarningForm .addEarlyWarningOrgList').append('<option value="' + data.data[i].id + '" selected>' + data.data[i].orgName + '</option>')
      }
    }).catch(function (err) {
      console.log(err);
    });
    // 添加时间
    var appearTime = moment().format('YYYY-MM-DD HH:mm:ss');
    $('#addEarlyWarningForm .appearTimeVal').val(appearTime);

    // 获取账号信息
    var getUserGetRet = getUserGet();
    getUserGetRet.then(function (data) {
      // console.log(data);    
      console.log(data);
      $(".addEarlyWarning-pop .appearPeople").val(data.data.name);
    }).catch(function (err) {
      console.log(err);
    });
  });
  //三色预警添加  关闭窗口
  $(".addEarlyWarning-pop").on("click", function (event) {
    if ($(event.target).is(".cd-popup-close1") || $(event.target).is(".addEarlyWarning-pop")) {
      // 清空添加的照片
      formData = {};
      formData1 = {};
      formData2 = {};
      formData3 = {};
      formData4 = {};
      $('#addEarlyWarningForm input').val('');

      $('#addEarlyWarningForm .earlyWarningPhoto .pic').attr('src', '');
      $('#addEarlyWarningForm .earlyWarningPhoto .pic').removeClass('opacity1');
      // 图片按顺序上传 除第一个框之外都 设禁用
      // $('#addEarlyWarningForm .earlyWarningPhoto li:not(:first)').find(".pic").attr("disabled", true);
      // $('#addEarlyWarningForm .earlyWarningPhoto li:not(:first)').addClass('earlyWarningPhotoDisabled');

      event.preventDefault();
      $(this).removeClass("is-visible3");
      //Modal验证销毁重构
      $("#addEarlyWarningForm").data('bootstrapValidator').destroy();
      $('#addEarlyWarningForm').data('bootstrapValidator', null);
      addEarlyWarningFormValidator();

      // 未选中的复选框 移除小叉 类
      $('.addEarlyWarning-pop .addEarlyWarningList .slight .iconfont').removeClass('active');
      $('.addEarlyWarning-pop .addEarlyWarningList .badly .iconfont').removeClass('active');
      $('.addEarlyWarning-pop .addEarlyWarningList .slight input').attr('checked', false);
      $('.addEarlyWarning-pop .addEarlyWarningList .badly input').attr('checked', false);

      $('#addEarlyWarningForm .leveliskVal').val('一般');
      levelisk = 1;
      // 数量
      $('.addEarlyWarning-pop .addEarlyWarningList .addEarlyWarningListLevelNumS').text(0);
      $('.addEarlyWarning-pop .addEarlyWarningList .addEarlyWarningListLevelNumM').text(0);
    }
  });

  var levelisk = 1;
  $("#addEarlyWarningModal .addEarlyWarningList label input[type='checkbox']").change(function () {
    var slightIndex = 0;
    var badlyIndex = 0;
    $(this).parent('label').siblings().find('input').attr("checked", false);
    $(this).parent('label').siblings().find('i').removeClass('active');
    $('#addEarlyWarningModal .addEarlyWarningList .slight input[type=checkbox]:checked').each(function (i, item) {
      $(".checkbox_item_slight:checked+.checkbox_icon_slight").addClass('active');
      slightIndex++;
      $(this).val('1');

    });
    $('#addEarlyWarningModal .addEarlyWarningList .badly input[type=checkbox]:checked').each(function (i, item) {
      $(".checkbox_item_badly:checked+.checkbox_icon_badly").addClass('active');
      earlyWarningCheckboxRed = true;
      badlyIndex++;
      $(this).val('1');
    });
    if (badlyIndex < 1) {
      if (slightIndex <= 1) {
        $('#addEarlyWarningModal .addEarlyWarningModal .leveliskVal').val('一般');
        levelisk = 1;
      } else if (slightIndex <= 4) {
        $('#addEarlyWarningModal .addEarlyWarningModal .leveliskVal').val('较大');
        levelisk = 2;
      } else {
        $('#addEarlyWarningModal .addEarlyWarningModal .leveliskVal').val('高危');
        levelisk = 3;
      }
    } else {
      $('#addEarlyWarningModal .addEarlyWarningModal .leveliskVal').val('高危');
      levelisk = 3;
    }
    // 未选中的复选框 移除小叉 类
    $('#addEarlyWarningModal .addEarlyWarningList .slight input[type=checkbox]').not("input:checked").next(".checkbox_icon_slight").removeClass('active');
    $('#addEarlyWarningModal .addEarlyWarningList .badly input[type=checkbox]').not("input:checked").next(".checkbox_icon_badly").removeClass('active');
    // 数量
    $('#addEarlyWarningModal .addEarlyWarningList .addEarlyWarningListLevelNumS').text(slightIndex);
    $('#addEarlyWarningModal .addEarlyWarningList .addEarlyWarningListLevelNumM').text(badlyIndex);
  });

  // 添加三色预警
  addEarlyWarningFormValidator();

  var uuid;
  // var imgId;
  function addEarlyWarningFormValidator() {
    $("#addEarlyWarningForm").bootstrapValidator({
      message: 'This value is not valid',
      feedbackIcons: {
        valid: 'glyphicon glyphicon-ok',
        invalid: 'glyphicon glyphicon-remove',
        validating: 'glyphicon glyphicon-refresh'
      },
      fields: {
        manager: {
          validators: {
            notEmpty: {
              message: '负责人不能为空'
            }
          }
        },
        telephone: {
          validators: {
            notEmpty: {
              message: '电话不能为空'
            }
          }
        },
        unit: {
          validators: {
            notEmpty: {
              message: '单位名称不能为空'
            }
          }
        },
        address: {
          validators: {
            notEmpty: {
              message: '地址不能为空'
            }
          }
        },
        latitudes: {
          validators: {
            notEmpty: {
              message: '经度不能为空'
            }
          }
        },
        longitude: {
          validators: {
            notEmpty: {
              message: '纬度不能为空'
            }
          }
        },
        orgId: {
          validators: {
            notEmpty: {
              message: '所属组织不能为空'
            }
          }
        },
        // appearTime: {
        //   validators: {
        //     notEmpty: {
        //       message: '上报时间不能为空'
        //     }
        //   }
        // },
        // appearPeople: {
        //   validators: {
        //     notEmpty: {
        //       message: '上报人不能为空'
        //     }
        //   }
        // },
        levelisk: {
          validators: {
            notEmpty: {
              message: '预警等级不能为空'
            }
          }
        }
      }
    }).on("success.form.bv", function (e) {
      e.preventDefault();
      $('.addEarlyWarningBtnSubmit').attr('disabled',true);
      // 唯一值 onlyValue 提交隐藏域的值
      var onlyValue = (new Date()).valueOf();
      $(".addEarlyWarning-pop .onlyValue").val(onlyValue);

      var $form = $(e.target);
      var timestamp = (new Date()).getTime();
      $("#addEarlyWarningForm .uuidVal").val(timestamp);
      var appearTimeVal = $('#addEarlyWarningForm .appearTimeVal').val();
      var appearPeople = $('#addEarlyWarningForm .appearPeople').val();
      var nextUrl;
      var leveliskNum = $('#addEarlyWarningForm .leveliskVal').val();
      console.log(leveliskNum);
      if (leveliskNum == '一般') {
        leveliskNum = 1;
      } else if (leveliskNum == '较大') {
        leveliskNum = 2;
      } else if (leveliskNum == '高危') {
        leveliskNum = 3;
      } else {
        leveliskNum = 1;
      }
      uuid = new Date().valueOf();
      nextUrl += $form.serialize();
      nextUrl += '&levelisk=' + levelisk;
      nextUrl += '&appearTime=' + appearTimeVal;
      nextUrl += '&appearPeople=' + appearPeople;
      var obj = $form.serializeObject();
      obj.levelisk = leveliskNum;
      obj.uuid = uuid;
      obj.appearTime = appearTimeVal;
      obj.appearPeople = appearPeople;

      console.log(JSON.stringify(obj));
      // vr str = '"'+JSON.stringify($form.serializeObject())+'"';
      var orgId = $("#addEarlyWarningForm .addEarlyWarningOrgList").val();
      var ret = getThreeColorSave(orgId, JSON.stringify(obj));
      ret.then(function (data) {
        console.log(data);
        $('.addEarlyWarningBtnSubmit').removeAttr('disabled');
        $('.addEarlyWarning-pop').removeClass('is-visible3');
        //Modal验证销毁重构
        $("#addEarlyWarningForm").data('bootstrapValidator').destroy();
        $('#addEarlyWarningForm').data('bootstrapValidator', null);
        addEarlyWarningFormValidator();
        $('#addEarlyWarningForm input').val('');
        $('#addEarlyWarningForm .addEarlyWarningList ul li').find("i").css('background', '');
        $("#addEarlyWarningForm").find(".pic").removeClass('opacity1');
        $('#addEarlyWarningForm .leveliskVal').val('一般');
        levelisk = 1;
        // 添加成功后重新渲染
        earlyWarningPageList(earlyWarningPageNum);
        tipModalFunc('添加成功!');
      }).catch(function (err) {
        console.log(err)
      });

      // 点击提交 提交图片到数据库

      $.ajax({
        url: "/threeColor/upload?uuid=" + uuid+'&onlyValue='+onlyValue,
        type: 'post',
        data: formData,
        contentType: false,
        processData: false,
        success: function (res) {
          console.log(res);
          formData = {};
        },
        error: function (res) {
          console.log(res);
        }
      });
      $.ajax({
        url: "/threeColor/upload?uuid=" + uuid+'&onlyValue='+onlyValue,
        type: 'post',
        data: formData1,
        contentType: false,
        processData: false,
        success: function (res) {
          console.log(res);
          formData1 = {};
        },
        error: function (res) {
          console.log(res);
        }
      });
      $.ajax({
        url: "/threeColor/upload?uuid=" + uuid+'&onlyValue='+onlyValue,
        type: 'post',
        data: formData2,
        contentType: false,
        processData: false,
        success: function (res) {
          console.log(res);
          formData2 = {};
        },
        error: function (res) {
          console.log(res);
        }
      });
      $.ajax({
        url: "/threeColor/upload?uuid=" + uuid+'&onlyValue='+onlyValue,
        type: 'post',
        data: formData3,
        contentType: false,
        processData: false,
        success: function (res) {
          console.log(res);
          formData3 = {};
        },
        error: function (res) {
          console.log(res);
        }
      });
      $.ajax({
        url: "/threeColor/upload?uuid=" + uuid+'&onlyValue='+onlyValue,
        type: 'post',
        data: formData4,
        contentType: false,
        processData: false,
        success: function (res) {
          console.log(res);
          formData4 = {};
        },
        error: function (res) {
          console.log(res);
        }
      });

      // 未选中的复选框 移除小叉 类
      $('.addEarlyWarning-pop .addEarlyWarningList .slight .iconfont').removeClass('active');
      $('.addEarlyWarning-pop .addEarlyWarningList .badly .iconfont').removeClass('active');
      $('.addEarlyWarning-pop .addEarlyWarningList .slight input').attr('checked', false);
      $('.addEarlyWarning-pop .addEarlyWarningList .badly input').attr('checked', false);

      $('#addEarlyWarningForm .earlyWarningPhoto .pic').attr('src', '');

      $('#addEarlyWarningForm .earlyWarningPhoto .pic').removeClass('opacity1');
      $('#addEarlyWarningForm .leveliskVal').val('一般');
      levelisk = 1;
      // 数量
      $('.addEarlyWarning-pop .addEarlyWarningList .addEarlyWarningListLevelNumS').text(0);
      $('.addEarlyWarning-pop .addEarlyWarningList .addEarlyWarningListLevelNumM').text(0);
    });
  }

  // 点击上传相片
  var picThat;
  var formData;
  var formData1;
  var formData2;
  var formData3;
  var formData4;
  var file;
  var imgUpload = 0;
  // var multipartFileArr = [];
  $("#addEarlyWarningModal .earlyWarningPhoto").on("click", '.pic', function () {
    var index = $(this).parent().index();
    console.log(index);
    console.log(this);
    $(this).parent().find(".upload").click(); //隐藏了input:file样式后，点击头像就可以本地上传
    $(this).parent().find(".upload").on("change", function (e) {
      imgUpload++;
      var objUrl = getObjectURL(this.files[0]); //获取图片的路径，该路径不是图片在本地的路径
      console.log(objUrl)
      picThat = this;
      console.log(this);

      // 图片倾斜问题 
      loadImage(
        // e.target.files[0],
        objUrl,
        function (img) {
          // document.body.appendChild(img);
          if (img.type === "error") {
            console.log("Error loading image " + imageUrl);
          } else {
            $(img).replaceAll($(picThat).prev('img'));
            $(img).addClass("pic");
            $(img).addClass("opacity1");
          }
        }, {
          orientation: true,
          maxWidth: 90,
          maxHeight: 70,
          minWidth: 90,
          minHeight: 70
        }
      );
      if (objUrl) {
        $(this).parent().find(".pic").attr("src", objUrl); //将图片路径存入src中，显示出图片
        $(this).parent().find(".pic").addClass('opacity1');
        // 当上传一张图片之后 第二个框可以上传图片 不再被禁用
        // $(this).parent().next().find(".upload").removeAttr('disabled');
        // $(this).parent().next().removeClass('earlyWarningPhotoDisabled');

      } else {
        $(this).parent().find(".pic").removeClass('opacity1');
      }

      file = picThat.files[0];
      console.log(file);
      if (index == 0) {
        formData = new FormData();
        formData.append("multipartFile", file);
        console.log(formData);
      } else if (index == 1) {
        formData1 = new FormData();
        formData1.append("multipartFile", file);
      } else if (index == 2) {
        formData2 = new FormData();
        formData2.append("multipartFile", file);
      } else if (index == 3) {
        formData3 = new FormData();
        formData3.append("multipartFile", file);
      } else if (index == 4) {
        formData4 = new FormData();
        formData4.append("multipartFile", file);
      }
    });
  });

  function getObjectURL(file) {
    var url = null;
    if (window.createObjectURL != undefined) { // basic
      url = window.createObjectURL(file);
    } else if (window.URL != undefined) { // mozilla(firefox)
      url = window.URL.createObjectURL(file);
    } else if (window.webkitURL != undefined) { // webkit or chrome
      url = window.webkitURL.createObjectURL(file);
    }
    return url;
  }
  // 添加 删除上传照片
  $('#addEarlyWarningModal .earlyWarningPhoto span').click(function () {
    $(this).siblings('.pic').attr('src', '')
    $(this).siblings('.pic').removeClass('opacity1');
    // 当删除图片之后 第二个框不可以上传图片 被禁用 
    // $(this).parent().next().find(".upload").attr("disabled", true);;
    // $(this).parent().next().addClass('earlyWarningPhotoDisabled');
    var index = $(this).parent().index();
    console.log(index)
    if (index == 0) {
      formData = {};
    } else if (index == 1) {
      formData1 = {};
    } else if (index == 2) {
      formData2 = {};
    } else if (index == 3) {
      formData3 = {};
    } else if (index == 4) {
      formData4 = {};
    }

  });
  // 查看详情修改里面 删除上传照片
  $('#checkEarlyWarningDetails .earlyWarningPhoto span').click(function () {
    $(this).siblings('.pic').attr('src', '');
    $(this).siblings('.pic').removeClass('opacity1');
    // 隐藏图片删除按钮
    $(this).hide();
    // // 当删除图片之后 第二个框不可以上传图片 被禁用 
    // $(this).parent().next().find(".upload").attr("disabled", true);;
    // $(this).parent().next().addClass('earlyWarningPhotoDisabled');
    var delid = $(this).siblings('.pic').attr("delid");
    $(this).siblings('.pic').attr("delid",'');
    if(delid){
      checkEarlyWarningdelid.push(delid);
    }
    
    var index = $(this).parent().index();
    console.log(index)
    if (index == 0) {
      detailsModifyformData = {};
    } else if (index == 1) {
      detailsModifyformData1 = {};
    } else if (index == 2) {
      detailsModifyformData2 = {};
    } else if (index == 3) {
      detailsModifyformData3 = {};
    } else if (index == 4) {
      detailsModifyformData4 = {};
    }
    // $.ajax({
    //   url: '/threeColor/delPicture?id=' + delid,
    //   type: 'post',
    //   data: {
    //     _method: "DELETE"
    //   },
    //   dataTpe: "json",
    //   success: function (res) {
    //     console.log(res);
    //   },
    //   error: function (res) {
    //     console.log(res);
    //   }
    // });

  });

  // 整改 删除上传照片
  $('.modifyEarlyWarningDetails-pop .earlyWarningPhoto span').click(function () {
    $(this).siblings('.pic').attr('src', '')
    $(this).siblings('.pic').removeClass('opacity1');
    // 当删除图片之后 第二个框不可以上传图片 被禁用 
    // $(this).parent().next().find(".upload").attr("disabled", true);;
    // $(this).parent().next().addClass('earlyWarningPhotoDisabled');
  });


  // 三色预警 查看详情
  var badlyNum;
  var slightNum;
  var checkImgId;
  earlyWarningSeeDetailsFunc();
  function earlyWarningSeeDetailsFunc(){
    $("body").on("click", '.earlyWarningSeeDetails', function (event) {
      event.preventDefault();
      $('#checkEarlyWarningDetails .modifyEarlyWarningDetailsBtn').removeClass('none');
      // 点击查看详情时初始化数据
      checkEarlyWarningDetailsrest();
      // 清除删除照片的数组
      checkEarlyWarningdelid=[];
      $('#lightgallery1 li').find('span').hide();
      $('#checkEarlyWarningDetails .list-unstyled1').show();
      $('#checkEarlyWarningDetails .list-unstyled2').hide();

      $(".checkEarlyWarningDetails-pop").addClass("is-visible3");
      seeDetails = $(this);
      // 获取所有信息
      // 获取唯一值
      var onlyValue = $(this).data("onlyvalue");
      var orgid = seeDetails.attr('orgid')
      $('#checkEarlyWarningDetails .checkEarlyWarningDetailsorgId').val(orgid);
      console.log(onlyValue);
      // 发送ajax 请求数据
      $.ajax({
        url: "/threeColor/getByOnlyValue?onlyValue=" + onlyValue,
        type: 'get',
        success: function (res) {
          console.log(res);
          checkImgId = res.data.content[0].uuid;
          // 获取图片主键
          // 获取图片id列表
          // 图片主键值
          var imgId = res.data.content[0].uuid;
          console.log(imgId);
          $.ajax({
            url: "/threeColor/getList?uuid=" + imgId,
            type: "get",
            success: function (res) {
              console.log(res.data);
              for (var i = 0; i < res.data.length; i++) {
                console.log(res.data[i][1],res.data[i][0])
                $("#lightgallery li").find(".pic").eq(i).attr("src", res.data[i][1]);
                // 给图片 赋id 以备删除用
                $("#lightgallery li").find(".pic").eq(i).attr("delid", res.data[i][0]);

                $("#lightgallery1 li").find(".pic").eq(i).attr("src", res.data[i][1]);
                // 给图片 赋id 以备删除用
                $("#lightgallery1 li").find(".pic").eq(i).attr("delid", res.data[i][0]);
                $("#lightgallery1 li").find(".pic").eq(i).attr("data-src", res.data[i][1]);
                $('#lightgallery1 li').find(".pic").eq(i).addClass('opacity1');
                $('#lightgallery1 li').eq(i).find('span').show();

                // $(this).data("onlyvalue")
                $("#lightgallery li").find(".pic").eq(i).attr("data-src", res.data[i][1]);
                $('#lightgallery li').find(".pic").eq(i).addClass('opacity1');
              }
              var checkEarlyWarningDetailsImgsHtml = template("checkEarlyWarningDetailsImgsTem", res);
              $("#lightgallery").html(checkEarlyWarningDetailsImgsHtml);
              // 点击图片放大并 可翻页的插件 初始化
              // $("[data-magnify=gallery]").magnify({
              //   "title": false,
              // });

              $('.galpop').galpop();

              // $('#lightgallery').on('click', '.pic', function() {
              //   var this_ = $(this);
              //   var images = this_.parents('#lightgallery').find('.pic');
              //   var imagesArr = new Array();
              //   $.each(images, function(i, image) {
              //       imagesArr.push($(image).children('img').attr('src'));
              //   });
              //   $.pictureViewer({
              //       images: imagesArr, //需要查看的图片，数据类型为数组
              //       initImageIndex: this_.index() + 1, //初始查看第几张图片，默认1
              //       scrollSwitch: true //是否使用鼠标滚轮切换图片，默认false（此功能需要jquery.mousewheel插件的支持）
              //   });
              // });
            },

            error: function (res) {
              console.log(res);
            }
          });
          var myid = res.data.content[0].organization.id;
          var appearTime = res.data.content[0].appearTime;
          appearTime = moment(appearTime).format('YYYY-MM-DD HH:mm:ss');
          console.log(myid)
          var leveliskStr = res.data.content[0].levelisk;
          console.log(leveliskStr)
          if (leveliskStr <= 1) {
            leveliskStr = '一般';
          } else if (leveliskStr == 2) {
            leveliskStr = '较大';
          } else if (leveliskStr == 3) {
            leveliskStr = '高危';
          } else {
            leveliskStr = '一般';
          }
          // 填数据
          $('.checkEarlyWarningDetails-pop .checkEarlyWarningDetailsManager').val(res.data.content[0].manager);
          $('.checkEarlyWarningDetails-pop .checkEarlyWarningDetailsTel').val(res.data.content[0].telephone);
          $('.checkEarlyWarningDetails-pop .checkEarlyWarningDetailsUnit').val(res.data.content[0].unit);
          $('.checkEarlyWarningDetails-pop .checkEarlyWarningDetailsAddress').val(res.data.content[0].address);
          $('.checkEarlyWarningDetails-pop .checkEarlyWarningDetailsLati').val(res.data.content[0].latitudes);
          $('.checkEarlyWarningDetails-pop .checkEarlyWarningDetailsLongi').val(res.data.content[0].longitude);
          $('.checkEarlyWarningDetails-pop .areaGridVal').val(res.data.content[0].areaGrid);
          $('.checkEarlyWarningDetails-pop .checkEarlyWarningDetailsorgId').val(myid);
          $('.checkEarlyWarningDetails-pop .checkEarlyWarningDetailsAppearTime').val(appearTime);
          $('.checkEarlyWarningDetails-pop .checkEarlyWarningDetailsAppearPeople').val(res.data.content[0].appearPeople);
          $('.checkEarlyWarningDetails-pop .checkEarlyWarningDetailsLevelisk').val(leveliskStr);
          $('.checkEarlyWarningDetails-pop .checkEarlyWarningDetailsRemarks').val(res.data.content[0].remarks);

          $('.checkEarlyWarningDetails-pop .onlyValue').val(onlyValue);

          badlyNum = 0;
          slightNum = 0;
          if (res.data.content[0].badly1) {
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly1']").next('i').addClass('active');
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly1']").prop("checked", true);
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly1']").val('1');
            badlyNum++;
          }
          if (res.data.content[0].slight1) {
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight1']").next('i').addClass('active');
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight1']").prop("checked", true);
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight1']").val('1');
            slightNum++;
          }
          if (res.data.content[0].badly2) {
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly2']").next('i').addClass('active');
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly2']").prop("checked", true);
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly2']").val('1');
            badlyNum++;
          }
          if (res.data.content[0].slight2) {
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight2']").next('i').addClass('active');
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight2']").prop("checked", true);
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight2']").val('1');
            slightNum++;
          }
          if (res.data.content[0].badly3) {
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly3']").next('i').addClass('active');
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly3']").prop("checked", true);
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly3']").val('1');
            badlyNum++;
          }
          if (res.data.content[0].slight3) {
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight3']").next('i').addClass('active');
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight3']").prop("checked", true);
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight3']").val('1');
            slightNum++;
          }
          if (res.data.content[0].badly4) {
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly4']").next('i').addClass('active');
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly4']").prop("checked", true);
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly4']").val('1');
            badlyNum++;
          }
          if (res.data.content[0].slight4) {
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight4']").next('i').addClass('active');
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight4']").prop("checked", true);
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight4']").val('1');
            slightNum++;
          }
          if (res.data.content[0].badly5) {
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly5']").next('i').addClass('active');
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly5']").prop("checked", true);
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly5']").val('1');
            badlyNum++;
          }
          if (res.data.content[0].slight5) {
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight5']").next('i').addClass('active');
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight5']").prop("checked", true);
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight5']").val('1');
            slightNum++;
          }
          if (res.data.content[0].badly6) {
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly6']").next('i').addClass('active');
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly6']").prop("checked", true);
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly6']").val('1');
            badlyNum++;
          }
          if (res.data.content[0].slight6) {
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight6']").next('i').addClass('active');
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight6']").prop("checked", true);
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight6']").val('1');
            slightNum++;
          }
          if (res.data.content[0].badly7) {
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly7']").next('i').addClass('active');
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly7']").prop("checked", true);
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly7']").val('1');
            badlyNum++;
          }
          if (res.data.content[0].slight7) {
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight7']").next('i').addClass('active');
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight7']").prop("checked", true);
            $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight7']").val('1');
            slightNum++;
          }
          $(".checkEarlyWarningDetails-pop .addEarlyWarningListLevelText .addEarlyWarningListLevelNumS").text(slightNum);
          $(".checkEarlyWarningDetails-pop .addEarlyWarningListLevelText .addEarlyWarningListLevelNumM").text(badlyNum);

        },
        error: function (res) {
          console.log(res);
        }
      })
    });
  }
  var modifyEarlyWarningFlag = true;
  // 三色预警 查看详情里面的修改
  $(".checkEarlyWarningDetails-pop .checkEarlyWarningDetailsBtnBox .modifyEarlyWarningDetailsBtn").on("click", function () {
    $("#checkEarlyWarningDetails").find("input").prop("disabled", false);
    $("#checkEarlyWarningDetails").find("select").prop("disabled", false);
    $("#checkEarlyWarningDetails").find("textarea").prop("disabled", false);
    $("#checkEarlyWarningDetails").find("input").removeClass("disabledStyle");
    $("#checkEarlyWarningDetails").find("select").removeClass("disabledStyle");
    $("#checkEarlyWarningDetails").find("textarea").removeClass("disabledStyle");
    $("#checkEarlyWarningDetails").find(".confirmEarlyWarningDetails").removeClass("none");
    $("#checkEarlyWarningDetails").find(".cancelEarlyWarningDetails").removeClass("none");
    $("#checkEarlyWarningDetails").find(".modifyEarlyWarningDetailsBtn").addClass("none");
    $('#checkEarlyWarningDetails .checkEarlyWarningDetailsLevelisk ').prop("disabled", true);
    $('#checkEarlyWarningDetails .checkEarlyWarningDetailsLevelisk ').addClass("disabledStyle");
    $('#checkEarlyWarningDetails .checkEarlyWarningDetailsAppearTime ').prop("disabled", true);
    $('#checkEarlyWarningDetails .checkEarlyWarningDetailsAppearTime ').addClass("disabledStyle");
    $('#checkEarlyWarningDetails .checkEarlyWarningDetailsAppearPeople ').prop("disabled", true);
    $('#checkEarlyWarningDetails .checkEarlyWarningDetailsAppearPeople ').addClass("disabledStyle");

    
    // 对照片
    // $("#lightgallery").find("li").removeClass("earlyWarningPhotoDisabled");

    modifyEarlyWarningFlag = false;
    $('#checkEarlyWarningDetails .list-unstyled1').hide();
    $('#checkEarlyWarningDetails .list-unstyled2').show();
  });

  // 查看详情 复选框 
  // var badlyNum = 0;
  // var slightNum = 0;
  $("#checkEarlyWarningDetails .addEarlyWarningList label input[type='checkbox']").change(function () {
    badlyNum = 0;
    slightNum = 0;
    console.log($(this).val());
    console.log($('#checkEarlyWarningDetails .addEarlyWarningList .slight input[type=checkbox]:checked'));
    $(this).parent('label').siblings().find('input').attr("checked", false);
    $(this).parent('label').siblings().find('i').removeClass('active');
    $('#checkEarlyWarningDetails .addEarlyWarningList .slight input[type=checkbox]:checked').each(function (i, item) {
      $("#checkEarlyWarningDetails .checkbox_item_slight:checked+.checkbox_icon_slight").addClass('active');
      slightNum++;
      $(this).val('1');
    });
    $('#checkEarlyWarningDetails .addEarlyWarningList .badly input[type=checkbox]:checked').each(function (i, item) {
      $("#checkEarlyWarningDetails .checkbox_item_badly:checked+.checkbox_icon_badly").addClass('active');
      badlyNum++;
      $(this).val('1');
    });
    if (badlyNum < 1) {
      if (slightNum <= 1) {
        $('#checkEarlyWarningDetails .leveliskVal').val('一般');
        levelisk = 1;
      } else if (slightNum <= 4) {
        $('#checkEarlyWarningDetails .leveliskVal').val('较大');
        levelisk = 2;
      } else {
        $('#checkEarlyWarningDetails .leveliskVal').val('高危');
        levelisk = 3;
      }
    } else {
      $('#checkEarlyWarningDetails .leveliskVal').val('高危');
      levelisk = 3;
    }
    // 未选中的复选框 移除小叉 类
    $('#checkEarlyWarningDetails .addEarlyWarningList .slight input[type=checkbox]').not("input:checked").next(".checkbox_icon_slight").removeClass('active');
    $('#checkEarlyWarningDetails .addEarlyWarningList .badly input[type=checkbox]').not("input:checked").next(".checkbox_icon_badly").removeClass('active');
    // 数量
    $('#checkEarlyWarningDetails .addEarlyWarningList .addEarlyWarningListLevelNumS').text(slightNum);
    $('#checkEarlyWarningDetails .addEarlyWarningList .addEarlyWarningListLevelNumM').text(badlyNum);
  });

  // 查看详情里面的 确认按钮 保存 事件
  modifyEarlyWarningValidator();

  function modifyEarlyWarningValidator() {
    $("#checkEarlyWarningDetailsForm").bootstrapValidator({
      message: 'This value is not valid',
      feedbackIcons: {
        valid: 'glyphicon glyphicon-ok',
        invalid: 'glyphicon glyphicon-remove',
        validating: 'glyphicon glyphicon-refresh'
      },
      fields: {
        manager: {
          validators: {
            notEmpty: {
              message: '负责人不能为空'
            }
          }
        },
        telephone: {
          validators: {
            notEmpty: {
              message: '电话不能为空'
            }
          }
        },
        unit: {
          validators: {
            notEmpty: {
              message: '单位名字不能为空'
            }
          }
        },
        address: {
          validators: {
            notEmpty: {
              message: '地址不能为空'
            }
          }
        },
        latitudes: {
          validators: {
            notEmpty: {
              message: '经度不能为空'
            }
          }
        },
        longitude: {
          validators: {
            notEmpty: {
              message: '纬度不能为空'
            }
          }
        },
        orgId: {
          validators: {
            notEmpty: {
              message: '所属组织不能为空'
            }
          }
        },
        levelisk: {
          validators: {
            notEmpty: {
              message: '预警等级不能为空'
            }
          }
        }
      }
    }).on("success.form.bv", function (e) {
      e.preventDefault();
      $('.modifyEarlyWarningDetailsBtn').attr('disabled',true);
      var $form = $(e.target);


      var timestamp = (new Date()).getTime();
      $("#checkEarlyWarningDetailsForm .uuidVal").val(timestamp);
      console.log($('#checkEarlyWarningDetailsForm .appearTimeVal').val());
      var appearTimeVal = $('#checkEarlyWarningDetailsForm .appearTimeVal').val();
      var appearPeople = $('#checkEarlyWarningDetailsForm .appearPeople').val();
      console.log($form.serialize());
      var nextUrl;
      // modifyuuid = new Date().valueOf();
      nextUrl += $form.serialize();
      nextUrl += '&levelisk=' + levelisk;
      nextUrl += '&appearTime=' + appearTimeVal;
      nextUrl += '&appearPeople=' + appearPeople;
      var obj = $form.serializeObject();
      console.log(obj);
      var leveliskStr = $('#checkEarlyWarningDetails .checkEarlyWarningDetailsLevelisk').val();
      console.log(leveliskStr)
      if (leveliskStr == '一般') {
        leveliskStr = 1;
      } else if (leveliskStr == '较大') {
        leveliskStr = 2;
      } else if (leveliskStr == '高危') {
        leveliskStr = 3;
      }
      obj.levelisk = leveliskStr;
      obj.uuid = checkImgId;
      obj.appearTime = appearTimeVal;
      obj.appearPeople = appearPeople;
      console.log(JSON.stringify(obj));
      // vr str = '"'+JSON.stringify($form.serializeObject())+'"';
        var id = seeDetails.attr("id");

      var orgid = $('#checkEarlyWarningDetails .checkEarlyWarningDetailsorgId').val();
      console.log(orgid)
      obj.id = id;
      // var orgId = $("#checkEarlyWarningDetailsForm .checkEarlyWarningDetailsorgId").val();
      console.log(id);
      var onlyvalue = seeDetails.data("onlyvalue");
      $("#checkEarlyWarningDetails .onlyValue").val(onlyvalue);
      var ret = getThreeColorSave(orgid, JSON.stringify(obj));
      ret.then(function (data) {
        console.log(data);
        $('.modifyEarlyWarningDetailsBtn').removeAttr('disabled');
        $('.checkEarlyWarningDetails-pop').removeClass('is-visible3');
        //Modal验证销毁重构
        $("#checkEarlyWarningDetailsForm").data('bootstrapValidator').destroy();
        $('#checkEarlyWarningDetailsForm').data('bootstrapValidator', null);
        modifyEarlyWarningValidator();
        $('#checkEarlyWarningDetailsForm input').val('');
        $('#checkEarlyWarningDetailsForm .addEarlyWarningList ul li').find("i").css('background', '');
        $("#checkEarlyWarningDetailsForm").find(".pic").removeClass('opacity1');
        earlyWarningPageList(earlyWarningPageNum);
        tipModalFunc('修改成功!');
        // 重置按钮 与禁用 样式
        $("#checkEarlyWarningDetails").find("input").prop("disabled", true);
        $("#checkEarlyWarningDetails").find("select").prop("disabled", true);
        $("#checkEarlyWarningDetails").find("input").addClass("disabledStyle");
        $("#checkEarlyWarningDetails").find("select").addClass("disabledStyle");
        $("#checkEarlyWarningDetails").find(".confirmEarlyWarningDetails").addClass("none");
        $("#checkEarlyWarningDetails").find(".cancelEarlyWarningDetails").addClass("none");
        $("#checkEarlyWarningDetails").find(".modifyEarlyWarningDetailsBtn").removeClass("none");
      }).catch(function (err) {
        console.log(err);
      });
      // 删除数据库中照片
      console.log(checkEarlyWarningdelid)
      for(var i=0;i<checkEarlyWarningdelid.length;i++){
        $.ajax({
          url: '/threeColor/delPicture?id=' + checkEarlyWarningdelid[i],
          type: 'post',
          data: {
            _method: "DELETE"
          },
          dataTpe: "json",
          success: function (res) {
            console.log(res);
          },
          error: function (res) {
            console.log(res);
          }
        });
      }

      // 点击提交 提交图片到数据库
      console.log(checkImgId)
      $.ajax({
        url: "/threeColor/upload?uuid=" + checkImgId+'&onlyValue='+onlyvalue,
        type: 'post',
        data: detailsModifyformData,
        contentType: false,
        processData: false,
        success: function (res) {
          console.log(res);
          detailsModifyformData = {};
          $('#checkEarlyWarningDetails #lightgallery1 li').eq(0).find('span').attr('src', '');
        },
        error: function (res) {
          console.log(res);
        }
      });
      $.ajax({
        url: "/threeColor/upload?uuid=" + checkImgId+'&onlyValue='+onlyvalue,
        type: 'post',
        data: detailsModifyformData1,
        contentType: false,
        processData: false,
        success: function (res) {
          console.log(res);
          detailsModifyformData1 = {};
          $('#checkEarlyWarningDetails #lightgallery1 li').eq(1).find('span').attr('src', '');
        },
        error: function (res) {
          console.log(res);
        }
      });
      $.ajax({
        url: "/threeColor/upload?uuid=" + checkImgId+'&onlyValue='+onlyvalue,
        type: 'post',
        data: detailsModifyformData2,
        contentType: false,
        processData: false,
        success: function (res) {
          console.log(res);
          detailsModifyformData2 = {};
          $('#checkEarlyWarningDetails #lightgallery1 li').eq(2).find('span').attr('src', '');
        },
        error: function (res) {
          console.log(res);
        }
      });
      $.ajax({
        url: "/threeColor/upload?uuid=" + checkImgId+'&onlyValue='+onlyvalue,
        type: 'post',
        data: detailsModifyformData3,
        contentType: false,
        processData: false,
        success: function (res) {
          console.log(res);
          detailsModifyformData3 = {};
          $('#checkEarlyWarningDetails #lightgallery1 li').eq(3).find('span').attr('src', '');
        },
        error: function (res) {
          console.log(res);
        }
      });
      $.ajax({
        url: "/threeColor/upload?uuid=" + checkImgId+'&onlyValue='+onlyvalue,
        type: 'post',
        data: detailsModifyformData4,
        contentType: false,
        processData: false,
        success: function (res) {
          console.log(res);
          detailsModifyformData4 = {};
          $('#checkEarlyWarningDetails #lightgallery1 li').eq(4).find('span').attr('src', '');
        },
        error: function (res) {
          console.log(res);
        }
      });



      // 未选中的复选框 移除小叉 类
      $('.addEarlyWarningList .slight .iconfont').removeClass('active');
      $('.addEarlyWarningList .badly .iconfont').removeClass('active');
      $('.addEarlyWarningList .slight input').attr('checked', false);
      $('.addEarlyWarningList .badly input').attr('checked', false);

      $('#modifyEarlyWarningDetails .earlyWarningPhoto .pic').attr('src', '');

      $('#modifyEarlyWarningDetails .earlyWarningPhoto .pic').removeClass('opacity1');
      $('#modifyEarlyWarningDetails .leveliskVal').val('一般');
      levelisk = 1;
      // 数量
      $('.addEarlyWarningList .addEarlyWarningListLevelNumS').text(0);
      $('.addEarlyWarningList .addEarlyWarningListLevelNumM').text(0);

    });
  }

  // 小叉 关闭窗口    
  $('.checkEarlyWarningDetails-pop .closeModal').on('click', function (event) {
    event.preventDefault();
    $('.checkEarlyWarningDetails-pop').removeClass('is-visible3');
  });
  // 三色预警查看详情  关闭窗口
  $(".checkEarlyWarningDetails-pop").on("click", function (event) {
    if (
      $(event.target).is(".cd-popup-close1") ||
      $(event.target).is(".checkEarlyWarningDetails-pop") || $(event.target).is(".cd-popup-close")
    ) {
      event.preventDefault();
      $(this).removeClass("is-visible3");
    }
  });




  // 点击 查看详情里面的修改的 上传相片
  var detailsModifyThat;
  var detailsModifyformData;
  var detailsModifyformData1;
  var detailsModifyformData2;
  var detailsModifyformData3;
  var detailsModifyformData4;
  var file;
  var imgUpload = 0;
  // var multipartFileArr = [];
  $("#checkEarlyWarningDetails .earlyWarningPhoto").on("click", '.pic', function () {
    if (!$(this).attr('src')) {
      var index = $(this).parent().index();
      $(this).parent().find(".upload").click(); //隐藏了input:file样式后，点击头像就可以本地上传
      $(this).parent().find(".upload").on("change", function (e) {
        imgUpload++;
        var objUrl = getObjectURL(this.files[0]); //获取图片的路径，该路径不是图片在本地的路径
        console.log(objUrl);
        detailsModifyThat = this;
        console.log(this);

        // 图片倾斜问题 
        loadImage(
          // e.target.files[0],
          objUrl,
          function (img) {
            // document.body.appendChild(img);
            if (img.type === "error") {
              console.log("Error loading image " + imageUrl);
            } else {
              $(img).replaceAll($(picThat).prev('img'));
              $(img).addClass("pic");
              $(img).addClass("opacity1");
            }
          }, {
            orientation: true,
            maxWidth: 90,
            maxHeight: 70,
            minWidth: 90,
            minHeight: 70
          }
        );
        if (objUrl) {
          $(this).parent().find(".pic").attr("src", objUrl); //将图片路径存入src中，显示出图片
          $(this).parent().find(".pic").addClass('opacity1');
          $(this).siblings('span').show();
          // 当上传一张图片之后 第二个框可以上传图片 不再被禁用
          // $(this).parent().next().find(".upload").removeAttr('disabled');
          // $(this).parent().next().removeClass('earlyWarningPhotoDisabled');
          // 记录是否存在照片的 状态
          // var isImg = $("#lightgallery li").find(".pic").attr("src");
          // var imgLength = $("#lightgallery li").length;
          // // console.log(imgLength);
          // for(var i = 0; i < imgLength; i++) {
          //   var isImg = $("#lightgallery li").find(".pic").eq(i).attr("src");
          //   console.log(isImg);
          //   if(!isImg) {            
          //     // $(this).parent().next().find(".upload").attr("disabled", true);;
          //     // $(this).parent().next().addClass('earlyWarningPhotoDisabled');
          //     $("#lightgallery li").find(".upload").eq(i).prop("disabled", false);
          //     $("#lightgallery li").find(".pic").eq(i).removeClass('earlyWarningPhotoDisabled');
          //     $("#lightgallery li").find(".upload").eq(i).next(".pic").prop("disabled", true);
          //     $("#lightgallery li").find(".pic").eq(i).next(".pic").addClass('earlyWarningPhotoDisabled');
          //   }
          // }

        } else {
          $(this).parent().find(".pic").removeClass('opacity1');
          $(this).parent().siblings().find('span').hide();
        }
        file = detailsModifyThat.files[0];
        if (index == 0) {
          detailsModifyformData = new FormData();
          detailsModifyformData.append("multipartFile", file);
        } else if (index == 1) {
          detailsModifyformData1 = new FormData();
          detailsModifyformData1.append("multipartFile", file);
        } else if (index == 2) {
          detailsModifyformData2 = new FormData();
          detailsModifyformData2.append("multipartFile", file);
        } else if (index == 3) {
          detailsModifyformData3 = new FormData();
          detailsModifyformData3.append("multipartFile", file);
        } else if (index == 4) {
          detailsModifyformData4 = new FormData();
          detailsModifyformData4.append("multipartFile", file);
        }
      });
    }
  });

  // -------------------------------------三色预警 整改--------------------------------------
  //将图片转换为Base64
function getImgToBase64(url, i,callback){
  var canvas = document.createElement('canvas'),
    ctx = canvas.getContext('2d'),
    img = new Image;
  img.crossOrigin = 'Anonymous';
  img.onload = function(){
    canvas.height = img.height;
    canvas.width = img.width;
    ctx.drawImage(img,0,0);
    var dataURL = canvas.toDataURL('image/png');
    callback(i, dataURL);
    canvas = null;
  };
  img.src = url;
}
//将base64转换为文件
function dataURLtoFile(dataurl, filename) {
  var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
  bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
  while(n--){
      u8arr[n] = bstr.charCodeAt(n);
  }
  return new File([u8arr], filename, {type:mime});
}
// 点击整改按钮
var modifyData = [];
var modifyImgData = [];
  $("#earlyWarningModal .tbodyList").on("click", '.modifyBtnStyle', function (event) {
    event.preventDefault();
    $(".modifyEarlyWarningDetails-pop").addClass("is-visible3");
    // 获取账号信息
    var getUserGetRet = getUserGet();
    getUserGetRet.then(function (data) {
      console.log(data);
      $("#modifyEarlyWarningDetailsForm .modifyEarlyWarningDetailsAppearPeople").val(data.data.name);
    }).catch(function (err) {
      console.log(err);
    });
    var onlyValue = $(this).attr('onlyValue');
    $('#modifyEarlyWarningDetails .onlyValue').val(onlyValue);
    $.ajax({
      url: "/threeColor/getByOnlyValue?onlyValue=" + onlyValue,
      type: 'get',
      success: function (res) {
        console.log(res);
        modifyData = res.data.content[0];
        var myid = res.data.content[0].organization.id;
        var appearTime = res.data.content[0].appearTime;
        appearTime = moment(appearTime).format('YYYY-MM-DD HH:mm:ss');
        console.log(myid);

        // 获取图片主键
        // 获取图片id列表
        // 图片主键值
        var imgId = res.data.content[0].uuid;
        console.log(imgId);
        $.ajax({
          url: "/threeColor/getList?uuid=" + imgId,
          type: "get",
          success: function (res) {
            console.log(res.data);
            modifyImgData = res.data;
            for(var i = 0; i < res.data.length; i++) {
              $("#modifyEarlyWarningDetails .earlyWarningPhoto li").find(".pic").eq(i).attr("src", res.data[i][1]);        
              $('#modifyEarlyWarningDetails .earlyWarningPhoto li').find(".pic").eq(i).addClass('opacity1');  


            }
            // console.log($("#lightgallery"));
            // 点击图片放大并 可翻页的插件 初始化
            // $("[data-magnify=gallery]").magnify({
            //   "title": false,
            // });
          },
          error: function (res) {
            console.log(res);
          }
        });

        // 填数据
        $('.modifyEarlyWarningDetails-pop .modifyEarlyWarningDetailsManager').val(res.data.content[0].manager);
        $('.modifyEarlyWarningDetails-pop .modifyEarlyWarningDetailsTel').val(res.data.content[0].telephone);
        $('.modifyEarlyWarningDetails-pop .modifyEarlyWarningDetailsUnit').val(res.data.content[0].unit);
        $('.modifyEarlyWarningDetails-pop .modifyEarlyWarningDetailsAddress').val(res.data.content[0].address);
        $('.modifyEarlyWarningDetails-pop .modifyEarlyWarningDetailsLati').val(res.data.content[0].latitudes);
        $('.modifyEarlyWarningDetails-pop .modifyEarlyWarningDetailsLongi').val(res.data.content[0].longitude);
        $('.modifyEarlyWarningDetails-pop .areaGridVal').val(res.data.content[0].areaGrid);
        $('.modifyEarlyWarningDetails-pop .modifyEarlyWarningDetailsorgId').val(myid);
        $('.modifyEarlyWarningDetails-pop .modifyEarlyWarningDetailsAppearTime').val(appearTime);
        // $('.modifyEarlyWarningDetails-pop .modifyEarlyWarningDetailsLevelisk').val('一般');
        $('.modifyEarlyWarningDetails-pop .modifyEarlyWarningDetailsRemarks').val('');
        var badlyNum = 0;
        var slightNum = 0;
        levelisk = 1;
        if (res.data.content[0].badly1) {
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly1']").next('i').addClass('active');
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly1']").prop("checked", true);
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly1']").val('1');
          badlyNum++;
        }
        if (res.data.content[0].slight1) {
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight1']").next('i').addClass('active');
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight1']").prop("checked", true);
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight1']").val('1');
          slightNum++;
        }
        if (res.data.content[0].badly2) {
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly2']").next('i').addClass('active');
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly2']").prop("checked", true);
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly2']").val('1');
          badlyNum++;
        }
        if (res.data.content[0].slight2) {
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight2']").next('i').addClass('active');
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight2']").prop("checked", true);
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight2']").val('1');
          slightNum++;
        }
        if (res.data.content[0].badly3) {
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly3']").next('i').addClass('active');
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly3']").prop("checked", true);
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly3']").val('1');
          badlyNum++;
        }
        if (res.data.content[0].slight3) {
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight3']").next('i').addClass('active');
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight3']").prop("checked", true);
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight3']").val('1');
          slightNum++;
        }
        if (res.data.content[0].badly4) {
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly4']").next('i').addClass('active');
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly4']").prop("checked", true);
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly4']").val('1');
          badlyNum++;
        }
        if (res.data.content[0].slight4) {
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight4']").next('i').addClass('active');
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight4']").prop("checked", true);
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight4']").val('1');
          slightNum++;
        }
        if (res.data.content[0].badly5) {
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly5']").next('i').addClass('active');
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly5']").prop("checked", true);
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly5']").val('1');
          badlyNum++;
        }
        if (res.data.content[0].slight5) {
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight5']").next('i').addClass('active');
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight5']").prop("checked", true);
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight5']").val('1');
          slightNum++;
        }
        if (res.data.content[0].badly6) {
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly6']").next('i').addClass('active');
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly6']").prop("checked", true);
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly6']").val('1');
          badlyNum++;
        }
        if (res.data.content[0].slight6) {
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight6']").next('i').addClass('active');
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight6']").prop("checked", true);
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight6']").val('1');
          slightNum++;
        }
        if (res.data.content[0].badly7) {
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly7']").next('i').addClass('active');
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly7']").prop("checked", true);
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly7']").val('1');
          badlyNum++;
        }
        if (res.data.content[0].slight7) {
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight7']").next('i').addClass('active');
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight7']").prop("checked", true);
          $(".modifyEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight7']").val('1');
          slightNum++;
        }
        if (badlyNum < 1) {
          if (slightNum <= 1) {
            $('.modifyEarlyWarningDetails-pop .leveliskVal').val('一般');
            levelisk = 1;
          } else if (slightNum <= 4) {
            $('.modifyEarlyWarningDetails-pop .leveliskVal').val('较大');
            levelisk = 2;
          } else {
            $('.modifyEarlyWarningDetails-pop .leveliskVal').val('高危');
            levelisk = 3;
          }
        } else {
          $('.modifyEarlyWarningDetails-pop .leveliskVal').val('高危');
          levelisk = 3;
        }
        $(".modifyEarlyWarningDetails-pop .addEarlyWarningListLevelText .addEarlyWarningListLevelNumS").text(slightNum);
        $(".modifyEarlyWarningDetails-pop .addEarlyWarningListLevelText .addEarlyWarningListLevelNumM").text(badlyNum);

      },
      error: function (res) {
        console.log(res);
      }
    });
  });


  // 整改部分 复选框  
  $("#modifyEarlyWarningDetails .addEarlyWarningList label input[type='checkbox']").change(function () {
    var badlyNum = 0;
    var slightNum = 0;
    $(this).parent('label').siblings().find('input').attr("checked", false);
    $(this).parent('label').siblings().find('i').removeClass('active');
    $('#modifyEarlyWarningDetails .addEarlyWarningList .slight input[type=checkbox]:checked').each(function (i, item) {
      $("#modifyEarlyWarningDetails .checkbox_item_slight:checked+.checkbox_icon_slight").addClass('active');
      slightNum++;
      $(this).val('1');
    });
    $('#modifyEarlyWarningDetails .addEarlyWarningList .badly input[type=checkbox]:checked').each(function (i, item) {
      $("#modifyEarlyWarningDetails .checkbox_item_badly:checked+.checkbox_icon_badly").addClass('active');
      badlyNum++;
      $(this).val('1');
    });
    if (badlyNum < 1) {
      if (slightNum <= 1) {
        $('#modifyEarlyWarningDetails .leveliskVal').val('一般');
        levelisk = 1;
      } else if (slightNum <= 4) {
        $('#modifyEarlyWarningDetails .leveliskVal').val('较大');
        levelisk = 2;
      } else {
        $('#modifyEarlyWarningDetails .leveliskVal').val('高危');
        levelisk = 3;
      }
    } else {
      $('#modifyEarlyWarningDetails .leveliskVal').val('高危');
      levelisk = 3;
    }
    // 未选中的复选框 移除小叉 类
    $('#modifyEarlyWarningDetails .addEarlyWarningList .slight input[type=checkbox]').not("input:checked").next(".checkbox_icon_slight").removeClass('active');
    $('#modifyEarlyWarningDetails .addEarlyWarningList .badly input[type=checkbox]').not("input:checked").next(".checkbox_icon_badly").removeClass('active');
    // 数量
    console.log(slightNum);
    console.log(badlyNum);
    $('#modifyEarlyWarningDetails .addEarlyWarningList .addEarlyWarningListLevelNumS').text(slightNum);
    $('#modifyEarlyWarningDetails .addEarlyWarningList .addEarlyWarningListLevelNumM').text(badlyNum);
  });

  // 点击上传相片
  var file;
  var imgUpload = 0;
  // var multipartFileArr = [];
  // 整改上传图片
  $("#modifyEarlyWarningDetails .earlyWarningPhoto .pic").click(function () {
    if(!$(this).attr('src')){
      var index = $(this).parent().index();
      $(this).parent().find(".upload").click(); //隐藏了input:file样式后，点击头像就可以本地上传
      $(this).parent().find(".upload").on("change", function () {
        imgUpload++;
        var objUrl = getObjectURL(this.files[0]); //获取图片的路径，该路径不是图片在本地的路径
        console.log(objUrl)
        modifypicThat = this;

        if (objUrl) {
          $(this).parent().find(".pic").attr("src", objUrl); //将图片路径存入src中，显示出图片
          $(this).parent().find(".pic").addClass('opacity1');
          // 当上传一张图片之后 第二个框可以上传图片 不再被禁用
          // $(this).parent().next().find(".upload").removeAttr('disabled');
          // $(this).parent().next().removeClass('earlyWarningPhotoDisabled');
        } else {
          $(this).parent().find(".pic").removeClass('opacity1');
        }

        file = modifypicThat.files[0];
        console.log(file)
        if (index == 0) {
          modifyformData = new FormData();
          modifyformData.append("multipartFile", file);
        } else if (index == 1) {
          modifyformData1 = new FormData();
          modifyformData1.append("multipartFile", file);
        } else if (index == 2) {
          modifyformData2 = new FormData();
          modifyformData2.append("multipartFile", file);
        } else if (index == 3) {
          modifyformData3 = new FormData();
          modifyformData3.append("multipartFile", file);
        } else if (index == 4) {
          modifyformData4 = new FormData();
          modifyformData4.append("multipartFile", file);
        }
        // for (i = 0; i < multipartFileArr.length; i++) {
        //   formData.append("multipartFile[" + i + "]", file[i]); 
        // }
      });
    }
  });
  // 三色预警整改
  var modifyuuid;
  // var imgId;
  modifyEarlyWarningDetailsValidator();
  function modifyEarlyWarningDetailsValidator() {
    $("#modifyEarlyWarningDetailsForm").bootstrapValidator({
      message: 'This value is not valid',
      feedbackIcons: {
        valid: 'glyphicon glyphicon-ok',
        invalid: 'glyphicon glyphicon-remove',
        validating: 'glyphicon glyphicon-refresh'
      },
      fields: {
        manager: {
          validators: {
            notEmpty: {
              message: '负责人不能为空'
            }
          }
        },
        telephone: {
          validators: {
            notEmpty: {
              message: '电话不能为空'
            }
          }
        },
        unit: {
          validators: {
            notEmpty: {
              message: '单位名字不能为空'
            }
          }
        },
        address: {
          validators: {
            notEmpty: {
              message: '地址不能为空'
            }
          }
        },
        latitudes: {
          validators: {
            notEmpty: {
              message: '经度不能为空'
            }
          }
        },
        longitude: {
          validators: {
            notEmpty: {
              message: '纬度不能为空'
            }
          }
        },
        orgId: {
          validators: {
            notEmpty: {
              message: '所属组织不能为空'
            }
          }
        },
        levelisk: {
          validators: {
            notEmpty: {
              message: '预警等级不能为空'
            }
          }
        }
      }
    }).on("success.form.bv", function (e) {
      e.preventDefault();
      $('.addEarlyWarningBtnSubmit').attr('disabled',true);
      var onlyValue = $('#modifyEarlyWarningDetailsForm .onlyValue').val();
      var $form = $(e.target);
      var timestamp = (new Date()).getTime();
      $("#modifyEarlyWarningDetailsForm .uuidVal").val(timestamp);
      var appearTimeVal = $('#modifyEarlyWarningDetailsForm .appearTimeVal').val();
      var appearPeople = $('#modifyEarlyWarningDetailsForm .appearPeople').val();
      console.log($form.serialize());
      var nextUrl;
      modifyuuid = new Date().valueOf();
      nextUrl += $form.serialize();
      nextUrl += '&levelisk=' + levelisk;
      nextUrl += '&appearTime=' + appearTimeVal;
      nextUrl += '&appearPeople=' + appearPeople;
      var obj = $form.serializeObject();
      obj.levelisk = levelisk;
      obj.uuid = modifyuuid;
      obj.appearTime = appearTimeVal;
      obj.appearPeople = appearPeople;
      console.log(JSON.stringify(obj));
      // vr str = '"'+JSON.stringify($form.serializeObject())+'"';
      var orgId = $("#modifyEarlyWarningDetails .modifyEarlyWarningDetailsorgId").val();
      var ret = getThreeColorSave(orgId, JSON.stringify(obj));
      ret.then(function (data) {
        console.log('==========================');
        earlyWarningPageList(earlyWarningPageNum);
        tipModalFunc('整改成功!');
        $('.addEarlyWarningBtnSubmit').removeAttr('disabled');
        $('.modifyEarlyWarningDetails-pop').removeClass('is-visible3');
        //Modal验证销毁重构
        $("#modifyEarlyWarningDetailsForm").data('bootstrapValidator').destroy();
        $('#modifyEarlyWarningDetailsForm').data('bootstrapValidator', null);
        modifyEarlyWarningDetailsValidator();
        $('#modifyEarlyWarningDetails input').val('');
        $('#modifyEarlyWarningDetails .addEarlyWarningList ul li').find("i").css('background', '');
        $("#modifyEarlyWarningDetails").find(".pic").removeClass('opacity1');
        // console.log(accountPage)
        // accountPageList(accountPage);
        // // 三色预警 获取总页数 点击分页渲染列表
        // accountSumPage(accountPage);
        // 添加成功后重新渲染
      }).catch(function (err) {
        console.log(err)
      });


      for(var i = 0;i<5;i++){
        var fileUrl = $("#modifyEarlyWarningDetails .earlyWarningPhoto li").find(".pic").eq(i).attr("src");     
        //将图片转换为base64
        getImgToBase64(fileUrl, i,function(d, data){
          var file = dataURLtoFile(data,i+'.png');
    　　　 console.log(file);
          if (d == 0) {
            modifyformData = new FormData();
            modifyformData.append("multipartFile", file);
            postPic(modifyformData);
            $('#modifyEarlyWarningDetails .earlyWarningPhoto li').eq(0).find('.pic').attr('src', '');
          } else if (d == 1) {
            modifyformData1 = new FormData();
            modifyformData1.append("multipartFile", file);
            postPic(modifyformData1);
            $('#modifyEarlyWarningDetails .earlyWarningPhoto li').eq(1).find('.pic').attr('src', '');
          } else if (d == 2) {
            modifyformData2 = new FormData();
            modifyformData2.append("multipartFile", file);
            postPic(modifyformData2);
            $('#modifyEarlyWarningDetails .earlyWarningPhoto li').eq(2).find('.pic').attr('src', '');
          } else if (d == 3) {
            modifyformData3 = new FormData();
            modifyformData3.append("multipartFile", file);
            postPic(modifyformData3);
            $('#modifyEarlyWarningDetails .earlyWarningPhoto li').eq(3).find('.pic').attr('src', '');
          } else if (d == 4) {
            modifyformData4 = new FormData();
            modifyformData4.append("multipartFile", file);
            postPic(modifyformData4);
            $('#modifyEarlyWarningDetails .earlyWarningPhoto li').eq(4).find('.pic').attr('src', '');
          }   
        });
      }


      // 点击提交 提交图片到数据库
      console.log(modifyuuid)
      function postPic(formData) {
        $.ajax({
          url: "/threeColor/upload?uuid=" + modifyuuid+'&onlyValue='+onlyValue,
          type: 'post',
          data: formData,
          contentType: false,
          processData: false,
          success: function (res) {
            console.log(res);
            formData = {};
          },
          error: function (res) {
            console.log(res);
          }
        });
      }

      //Modal验证销毁重构
      $("#modifyEarlyWarningDetailsForm").data('bootstrapValidator').destroy();
      $('#modifyEarlyWarningDetailsForm').data('bootstrapValidator', null);
      modifyEarlyWarningDetailsValidator();

      // 未选中的复选框 移除小叉 类
      $('.addEarlyWarningList .slight .iconfont').removeClass('active');
      $('.addEarlyWarningList .badly .iconfont').removeClass('active');
      $('.addEarlyWarningList .slight input').attr('checked', false);
      $('.addEarlyWarningList .badly input').attr('checked', false);


      $('#modifyEarlyWarningDetails .earlyWarningPhoto .pic').removeClass('opacity1');
      $('#modifyEarlyWarningDetails .leveliskVal').val('一般');
      levelisk = 1;
      // 数量
      $('.addEarlyWarningList .addEarlyWarningListLevelNumS').text(0);
      $('.addEarlyWarningList .addEarlyWarningListLevelNumM').text(0);
      // ------------

    });
  }
  // 三色预警整改  关闭窗口
  $(".modifyEarlyWarningDetails-pop").on("click", function (event) {
    if (
      $(event.target).is(".cd-popup-close1") ||
      $(event.target).is(".modifyEarlyWarningDetails-pop")
    ) {
      event.preventDefault();
      $(this).removeClass("is-visible3");

      // modifyformData = {};
      modifyformData1 = {};
      modifyformData2 = {};
      modifyformData3 = {};
      modifyformData4 = {};
      //Modal验证销毁重构
      $("#modifyEarlyWarningDetailsForm").data('bootstrapValidator').destroy();
      $('#modifyEarlyWarningDetailsForm').data('bootstrapValidator', null);
      modifyEarlyWarningDetailsValidator();

      // 未选中的复选框 移除小叉 类
      $('.addEarlyWarningList .slight .iconfont').removeClass('active');
      $('.addEarlyWarningList .badly .iconfont').removeClass('active');
      $('.addEarlyWarningList .slight input').attr('checked', false);
      $('.addEarlyWarningList .badly input').attr('checked', false);

      $('#modifyEarlyWarningDetails .earlyWarningPhoto .pic').attr('src', '');

      $('#modifyEarlyWarningDetails .earlyWarningPhoto .pic').removeClass('opacity1');
      $('#modifyEarlyWarningDetails .leveliskVal').val('一般');
      levelisk = 1;
      // 数量
      $('.addEarlyWarningList .addEarlyWarningListLevelNumS').text(0);
      $('.addEarlyWarningList .addEarlyWarningListLevelNumM').text(0);
    }
  });
    // -------------------三色预警下载二维码-------------------
    //创建二维码
    function createQRCode(id, url, width, height, src, label) {
      $('.' + id).empty();
      jQuery('.' + id).qrcode({
        render: 'canvas',
        text: url,
        width : width,              //二维码的宽度  
        height : height,            //二维码的高度  
        imgWidth : width/4,         //图片宽
        imgHeight : height/4,       //图片高
        src: src,            //图片中央的二维码
        ecLevel:'H',//误差校正水平选择最高级
        mode: 1, //label模式选择2
        label: label,
        fontname: 'Arial',
        fontcolor: '#458fd2',
        background : "#ffffff",       //二维码的后景色  
        foreground : "#000",        //二维码的前景色  
        typeNumber: -1,
        mSize: 0.019,
        size: 180,
        mPosX: 0.5,
        mPosY: 0.99,  //logo 文字的位置
        quiet: 3  // 安静区域 即周边空白区域
      });
    }
    function codeInit(onlyvalue, qrCodeName) {
      createQRCode('earlyWarningQrcode'+onlyvalue, onlyvalue, 180, 180, "img/logo.png", qrCodeName);
    }

    // 查看详情 查看二维码
    $(".earlyWarningQRCodeBtn").on("click", function(){
        $(".checkEarlyWarningDetailsQrCode-pop").addClass("is-visible3");
        var onlyvalue = seeDetails.attr("data-onlyvalue");
        var qrCodeName = seeDetails.attr("data-qrCode");
        $(".checkEarlyWarningDetailsQrCodeCode-pop").text(onlyvalue);
        createQRCode('checkEarlyWarningDetailsQrCodeImg', onlyvalue, 180, 180, "img/logo.png", qrCodeName);
        var canvas = $(".checkEarlyWarningDetailsQrCodeImg").find("canvas").get(0);
        // console.log(canvas);
    })
    // 关闭 二维码页面
    $(".checkEarlyWarningDetailsQrCode-pop").on("click", function (event) {
      if (
        $(event.target).is(".checkEarlyWarningDetailsQrCodeReturn") ||
        $(event.target).is(".checkEarlyWarningDetailsQrCode-pop")
      ) {
        event.preventDefault();
        $(this).removeClass("is-visible3");
      }
    });

    // 点击下载二维码
    $('#earlyWarningModal .tbodyList').on('click','.earlyWarningsaveQrCode',function (){
      var onlyvalue = $(this).siblings('.earlyWarningRectifyBtn').attr('onlyvalue');
      var unit = $(this).parent().siblings().eq(3).text();
      console.log(onlyvalue,unit, $(this).siblings('.earlyWarningQrcode1'),$(this))
      codeInit(onlyvalue, unit);
      $(this).siblings('a').attr('download',unit+'.jpg');
      var canvas = $(this).siblings('.earlyWarningQrcode1').find("canvas").get(0);
      console.log(canvas);
      try {//解决IE转base64时缓存不足，canvas转blob下载
        var blob = canvas.msToBlob();
        navigator.msSaveBlob(blob, 'qrcode.jpg');
      } catch (e) {//如果为其他浏览器，使用base64转码下载
        var url = canvas.toDataURL('image/jpeg');
        $(this).siblings('a').attr('href', url).get(0).click();
      }
      return false;
    });
      // 勾选，批量下载二维码
  $("#earlyWarningDownBtn").on("click", function () {
    
    $("#earlyWarningModal .tbodyList").find(":checked").each(function (index, ele) {
      var onlyvalue = $(this).attr("onlyvalue");
      var unit = $(this).parent().siblings().eq(2).text();
      console.log(onlyvalue,unit, $(this).parent().parent().find('.earlyWarningQrcode1'),$(this));
      codeInit(onlyvalue, unit);
      $(this).parent().parent().find('a').attr('download',unit+'.jpg');
      var canvas = $(this).parent().parent().find('.earlyWarningQrcode1').find("canvas").get(0);
      console.log(canvas);
      try {//解决IE转base64时缓存不足，canvas转blob下载
        var blob = canvas.msToBlob();
        navigator.msSaveBlob(blob, 'qrcode.jpg');
      } catch (e) {//如果为其他浏览器，使用base64转码下载
        var url = canvas.toDataURL('image/jpeg');
        $(this).parent().parent().find('a').attr('href', url).get(0).click();
      }
      $("#earlyWarningSelectAll").prop("checked", false);
      $(this).prop("checked", false);
    });
  });

});
//--------------------

  // 三色预警点击查看详情时初始化数据，地图上的查看详情和三色预警列表的查看详情
  function checkEarlyWarningDetailsrest(){
    $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul").find('i').removeClass('active');
    // 重置按钮 与禁用 样式
    $("#checkEarlyWarningDetails").find("input").prop("disabled", true);
    $("#checkEarlyWarningDetails").find("select").prop("disabled", true);
    $("#checkEarlyWarningDetails").find("input").addClass("disabledStyle");
    $("#checkEarlyWarningDetails").find("select").addClass("disabledStyle");
    $("#checkEarlyWarningDetails").find(".confirmEarlyWarningDetails").addClass("none");
    $("#checkEarlyWarningDetails").find(".cancelEarlyWarningDetails").addClass("none");
    $("#checkEarlyWarningDetails").find(".modifyEarlyWarningDetailsBtn").removeClass("none");

    // 清除图片
    $(".checkEarlyWarningDetails-pop .earlyWarningPhoto ul li").find("img").attr("src", '');
    $(".checkEarlyWarningDetails-pop .earlyWarningPhoto ul li").find(".pic").removeClass('opacity1');

    // 未选中的复选框 移除小叉 类
    $('#checkEarlyWarningDetails .addEarlyWarningList .slight .iconfont').removeClass('active');
    $('#checkEarlyWarningDetails .addEarlyWarningList .badly .iconfont').removeClass('active');
    $('#checkEarlyWarningDetails .addEarlyWarningList .slight input').attr('checked', false);
    $('#checkEarlyWarningDetails .addEarlyWarningList .badly input').attr('checked', false);

    $('#checkEarlyWarningDetails .leveliskVal').val('一般');
    levelisk = 1;
    // 数量
    $('#checkEarlyWarningDetails .addEarlyWarningList .addEarlyWarningListLevelNumS').text(0);
    $('#checkEarlyWarningDetails .addEarlyWarningList .addEarlyWarningListLevelNumM').text(0);

    detailsModifyformData = {};
    detailsModifyformData1 = {};
    detailsModifyformData2 = {};
    detailsModifyformData3 = {};
    detailsModifyformData4 = {};
  }
  // 地图上的查看详情点击查看详情
function earlyWarningSeeDetailsFunc1(){
  $("body .earlyWarningSeeDetails").on("click", function (event) {
    event.preventDefault();
    seeDetails = $(this);
    console.log($(this))
    // 点击查看详情时初始化数据
    checkEarlyWarningDetailsrest();
    // 清除删除照片的数组
    checkEarlyWarningdelid=[];
    $('#lightgallery1 li').find('span').hide();
    $('#checkEarlyWarningDetails .list-unstyled1').show();
    $('#checkEarlyWarningDetails .list-unstyled2').hide();

    $(".checkEarlyWarningDetails-pop").addClass("is-visible3");
    // 获取所有信息
    // 获取唯一值
    var onlyValue = $(this)[0].attributes.onlyValue.value;
    var orgid = $(this).attr('orgid')
    console.log($(this),onlyValue)
    $('#checkEarlyWarningDetails .checkEarlyWarningDetailsorgId').val(orgid);
    console.log(onlyValue);
    // 发送ajax 请求数据
    $.ajax({
      url: "/threeColor/getByOnlyValue?onlyValue=" + onlyValue,
      type: 'get',
      success: function (res) {
        console.log(res);
        checkImgId = res.data.content[0].uuid;
        // 获取图片主键
        // 获取图片id列表
        // 图片主键值
        var imgId = res.data.content[0].uuid;
        console.log(imgId);
        $.ajax({
          url: "/threeColor/getList?uuid=" + imgId,
          type: "get",
          success: function (res) {
            console.log(res);
            for (var i = 0; i < res.data.length; i++) {

              $("#lightgallery li").find(".pic").eq(i).attr("src", + res.data[i][1]);
              // 给图片 赋id 以备删除用
              $("#lightgallery li").find(".pic").eq(i).attr("delid", res.data[i][0]);

              $("#lightgallery1 li").find(".pic").eq(i).attr("src", res.data[i][1]);
              // 给图片 赋id 以备删除用
              $("#lightgallery1 li").find(".pic").eq(i).attr("delid", res.data[i][0]);
              $("#lightgallery1 li").find(".pic").eq(i).attr("data-src", res.data[i][1]);
              $('#lightgallery1 li').find(".pic").eq(i).addClass('opacity1');
              $('#lightgallery1 li').eq(i).find('span').show();

              // $(this).data("onlyvalue")
              $("#lightgallery li").find(".pic").eq(i).attr("data-src", res.data[i][1]);
              $('#lightgallery li').find(".pic").eq(i).addClass('opacity1');
            }
            var checkEarlyWarningDetailsImgsHtml = template("checkEarlyWarningDetailsImgsTem", res);
            $("#lightgallery").html(checkEarlyWarningDetailsImgsHtml);
            console.log($("#lightgallery"));
            // 点击图片放大并 可翻页的插件 初始化
            // $("[data-magnify=gallery]").magnify({
            //   "title": false,
            // });

            $('.galpop').galpop();

            // $('#lightgallery').on('click', '.pic', function() {
            //   var this_ = $(this);
            //   var images = this_.parents('#lightgallery').find('.pic');
            //   var imagesArr = new Array();
            //   $.each(images, function(i, image) {
            //       imagesArr.push($(image).children('img').attr('src'));
            //   });
            //   $.pictureViewer({
            //       images: imagesArr, //需要查看的图片，数据类型为数组
            //       initImageIndex: this_.index() + 1, //初始查看第几张图片，默认1
            //       scrollSwitch: true //是否使用鼠标滚轮切换图片，默认false（此功能需要jquery.mousewheel插件的支持）
            //   });
            // });
          },

          error: function (res) {
            console.log(res);
          }
        });
        var myid = res.data.content[0].organization.id;
        var appearTime = res.data.content[0].appearTime;
        appearTime = moment(appearTime).format('YYYY-MM-DD HH:mm:ss');
        console.log(myid)
        var leveliskStr = res.data.content[0].levelisk;
        console.log(leveliskStr)
        if (leveliskStr <= 1) {
          leveliskStr = '一般';
        } else if (leveliskStr == 2) {
          leveliskStr = '较大';
        } else if (leveliskStr == 3) {
          leveliskStr = '高危';
        } else {
          leveliskStr = '一般';
        }
        // 填数据
        $('.checkEarlyWarningDetails-pop .checkEarlyWarningDetailsManager').val(res.data.content[0].manager);
        $('.checkEarlyWarningDetails-pop .checkEarlyWarningDetailsTel').val(res.data.content[0].telephone);
        $('.checkEarlyWarningDetails-pop .checkEarlyWarningDetailsUnit').val(res.data.content[0].unit);
        $('.checkEarlyWarningDetails-pop .checkEarlyWarningDetailsAddress').val(res.data.content[0].address);
        $('.checkEarlyWarningDetails-pop .checkEarlyWarningDetailsLati').val(res.data.content[0].latitudes);
        $('.checkEarlyWarningDetails-pop .checkEarlyWarningDetailsLongi').val(res.data.content[0].longitude);
        $('.checkEarlyWarningDetails-pop .areaGridVal').val(res.data.content[0].areaGrid);
        $('.checkEarlyWarningDetails-pop .checkEarlyWarningDetailsorgId').val(myid);
        $('.checkEarlyWarningDetails-pop .checkEarlyWarningDetailsAppearTime').val(appearTime);
        $('.checkEarlyWarningDetails-pop .checkEarlyWarningDetailsAppearPeople').val(res.data.content[0].appearPeople);
        $('.checkEarlyWarningDetails-pop .checkEarlyWarningDetailsLevelisk').val(leveliskStr);
        $('.checkEarlyWarningDetails-pop .checkEarlyWarningDetailsRemarks').val(res.data.content[0].remarks);

        $('.checkEarlyWarningDetails-pop .onlyValue').val(onlyValue);

        badlyNum = 0;
        slightNum = 0;
        if (res.data.content[0].badly1) {
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly1']").next('i').addClass('active');
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly1']").prop("checked", true);
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly1']").val('1');
          badlyNum++;
        }
        if (res.data.content[0].slight1) {
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight1']").next('i').addClass('active');
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight1']").prop("checked", true);
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight1']").val('1');
          slightNum++;
        }
        if (res.data.content[0].badly2) {
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly2']").next('i').addClass('active');
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly2']").prop("checked", true);
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly2']").val('1');
          badlyNum++;
        }
        if (res.data.content[0].slight2) {
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight2']").next('i').addClass('active');
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight2']").prop("checked", true);
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight2']").val('1');
          slightNum++;
        }
        if (res.data.content[0].badly3) {
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly3']").next('i').addClass('active');
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly3']").prop("checked", true);
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly3']").val('1');
          badlyNum++;
        }
        if (res.data.content[0].slight3) {
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight3']").next('i').addClass('active');
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight3']").prop("checked", true);
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight3']").val('1');
          slightNum++;
        }
        if (res.data.content[0].badly4) {
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly4']").next('i').addClass('active');
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly4']").prop("checked", true);
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly4']").val('1');
          badlyNum++;
        }
        if (res.data.content[0].slight4) {
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight4']").next('i').addClass('active');
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight4']").prop("checked", true);
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight4']").val('1');
          slightNum++;
        }
        if (res.data.content[0].badly5) {
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly5']").next('i').addClass('active');
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly5']").prop("checked", true);
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly5']").val('1');
          badlyNum++;
        }
        if (res.data.content[0].slight5) {
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight5']").next('i').addClass('active');
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight5']").prop("checked", true);
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight5']").val('1');
          slightNum++;
        }
        if (res.data.content[0].badly6) {
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly6']").next('i').addClass('active');
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly6']").prop("checked", true);
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly6']").val('1');
          badlyNum++;
        }
        if (res.data.content[0].slight6) {
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight6']").next('i').addClass('active');
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight6']").prop("checked", true);
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight6']").val('1');
          slightNum++;
        }
        if (res.data.content[0].badly7) {
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly7']").next('i').addClass('active');
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly7']").prop("checked", true);
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='badly7']").val('1');
          badlyNum++;
        }
        if (res.data.content[0].slight7) {
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight7']").next('i').addClass('active');
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight7']").prop("checked", true);
          $(".checkEarlyWarningDetails-pop .addEarlyWarningList ul input[name='slight7']").val('1');
          slightNum++;
        }
        $(".checkEarlyWarningDetails-pop .addEarlyWarningListLevelText .addEarlyWarningListLevelNumS").text(slightNum);
        $(".checkEarlyWarningDetails-pop .addEarlyWarningListLevelText .addEarlyWarningListLevelNumM").text(badlyNum);

      },
      error: function (res) {
        console.log(res);
      }
    });
    $('#checkEarlyWarningDetails .modifyEarlyWarningDetailsBtn').addClass('none');
  });

}